package com.qf.swaggerspringbootstart;

import com.qf.swaggerspringbootstart.properties.SyProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;


@EnableConfigurationProperties(SyProperties.class)
//@ConfigurationProperties(prefix = "sy.pick")
@Configuration
public class SwaggerSpringBootStartApplication {
@Bean
public Docket docket(SyProperties syProperties){
    //创建需要的对象
    Docket docket = new Docket(DocumentationType.SWAGGER_2);
    //配置信息
    //建造者模式的实例
    ApiInfo apiInfo = new ApiInfoBuilder().title(syProperties.getTitle()).version(syProperties.getVersion())
            .description(syProperties.getDescription())
            .contact(new Contact(syProperties.getContactsName(), syProperties.getContactsUrl(), syProperties.getContactsEmail()))
            .build();//build方法会根据上面设置好的配置信息创建一个ApiInfo对象
    docket.apiInfo(apiInfo);
    //定制swagger只扫描我们自己项目的controller，不要扫描mvc
    docket.select().apis(RequestHandlerSelectors.basePackage(syProperties.getBasePackageUrl())).build();

    //返回该对象
    return docket;
}



}
